from datetime import datetime
import uuid
from flask import Flask
from flask_tui_editor import TUIEditor
from flask_wtf.csrf import CSRFProtect
from blueprints.auth import auth_bp
from blueprints.posts import posts_bp
from blueprints.admin import admin_bp
from blueprints.uploads import uploads_bp

app = Flask(__name__)
app.secret_key = str(uuid.uuid4())

# 注册蓝图
app.register_blueprint(auth_bp)
app.register_blueprint(posts_bp)
app.register_blueprint(admin_bp)
app.register_blueprint(uploads_bp)

# 初始化扩展
csrf = CSRFProtect(app)
tui_editor = TUIEditor(app)


@app.context_processor
def inject_current_year():
    return {'current_year': datetime.now().year}


if __name__ == '__main__':
    app.run(debug=True)
